package com.mskj.zxmy.service.serviceImpl;

import com.mskj.zxmy.entity.Gy02ProductRepository;
import com.mskj.zxmy.dto.ProductDetailDTO;
import com.mskj.zxmy.mapper.Gy02ProductRepositoryMapper;
import com.mskj.zxmy.service.Gy02ProductRepositoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 产品信息表服务实现
 */
@Service
public class Gy02ProductRepositoryServiceImpl implements Gy02ProductRepositoryService {
    @Autowired
    private Gy02ProductRepositoryMapper gy02ProductRepositoryMapper;

    /**
     * 根据任务流水号查询工单（产品信息）
     *
     * @param id 任务id号
     * @return 产品信息工单
     */
    @Override
    public Gy02ProductRepository getByMissionStream(String id) {
        return gy02ProductRepositoryMapper.selectByMissionStream(id);
    }

    /**
     * 根据id查询产品详情
     *
     * @param id 产品id
     * @return 产品详情
     */
    @Override
    public Gy02ProductRepository getById(String id) {
        return gy02ProductRepositoryMapper.selectById(id);
    }

    /**
     * 根据任务流水号查询产品详情DTO
     *
     * @param id 任务流水号
     * @return 产品详情DTO
     */
    @Override
    public ProductDetailDTO getProductDetailByMissionStream(String id) {
        // 1. 查工单
        Gy02ProductRepository workOrder = this.getByMissionStream(id);
        if (workOrder == null) {
            return null;
        }
        // 2. 查产品详情
        Gy02ProductRepository productDetail = this.getById(workOrder.getProductName());
        if (productDetail == null) {
            return null;
        }
        // 3. 组装DTO
        ProductDetailDTO dto = new ProductDetailDTO();
        dto.setProductId(Integer.valueOf(productDetail.getId()));
        dto.setProductNumber(productDetail.getProductNumber());
        dto.setProductSpecifications(productDetail.getMaterialCategory() + " " + productDetail.getTypeOfProduct());
        dto.setProductName(productDetail.getProductName());
        dto.setBrand(productDetail.getBrand());
        dto.setEnvironmentalProtectionLevel(productDetail.getEnvironmentalProtectionLevel());
        dto.setNumber(productDetail.getNumberCompleted());//等级
        return dto;
    }
} 